< previous page page_179 next page >

Page 179
Solution 11
Registry Games, Part 1
If you solved this problem in less than five minutes, congratulations! You've learned the most important part of API programming: Always double-check your code for careless and obvious mistakes.
If you didn't solve the problem quickly, you'll probably kick yourself.
First Problem
Your best hint is in the error message Unable to open the registry key: The system cannot find the file specified. Could it be that the hKey or lpSubKey parameters are wrong?
The hKey parameter is the constant from the api32.txt file. Although this certainly could be in error, it might be more efficient to check the lpSubKey parameter before spending time checking the HKEY_LOCAL_MACHINE constant against the original Microsoft header files.
The subkey is defined as follows:
controlkey = "SYSTEM/CurrentControlSet/Control"
Do you see it?
controlkey = "SYSTEM\CurrentControlSet\Control"
How about now?
Second Problem
Once you fix the string to use the correct backslash, you will receive the error message Unable to open the registry key: Access is denied if you are running on Windows NT.
That's odd. The KEY_READ constant is a logical Or combination of all of the constants that one could possibly need to open a key, read and enumerate its subkeys, and read the data values.
To solve this problem, take a closer look at the declaration for the RegOpenKeyEx function and the code that calls the function:

 
< previous page page_179 next page >